﻿using System;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using Microsoft.Practices.Unity;

namespace Se.Framework.Common
{
    public class CallContextLifetimeManager : LifetimeManager
    {
        private readonly string id = Guid.NewGuid().ToString();

        public string Id
        {
            get
            {
                return this.id;
            }
        }

        public override object GetValue()
        {
            return CallContext.GetData(id);
        }

        public override void SetValue(object newValue)
        {
            CallContext.SetData(id, newValue);
        }

        public override void RemoveValue()
        {
            CallContext.FreeNamedDataSlot(id);
        }
    }
}
